package com.train.user.controller;

import com.train.common.annotation.Anonymous;
import com.train.common.core.controller.BaseController;
import com.train.common.core.domain.AjaxResult;
import com.train.common.core.page.TableDataInfo;
import com.train.user.domain.SysTopic;
import com.train.user.service.SysTopicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 话题管理 控制器
 * 
 * @author train
 */
@RestController
@RequestMapping("/user/topic")
public class SysTopicController extends BaseController {

    @Autowired
    private SysTopicService topicService;

    /**
     * 添加话题
     */
    @Anonymous
    @PostMapping
    public AjaxResult add(@RequestBody SysTopic topic) {
        return toAjax(topicService.save(topic));
    }

    /**
     * 查询话题列表
     */
    @GetMapping("/list")
    public TableDataInfo list(SysTopic topic) {
        startPage();
        List<SysTopic> list = topicService.list();
        return getDataTable(list);
    }

    /**
     * 根据ID查询话题详情
     */
    @GetMapping(value = "/{topicId}")
    public AjaxResult getInfo(@PathVariable("topicId") Long topicId) {
        return AjaxResult.success(topicService.getById(topicId));
    }

    /**
     * 修改话题
     */
    @PutMapping
    public AjaxResult edit(@RequestBody SysTopic topic) {
        return toAjax(topicService.updateById(topic));
    }

    /**
     * 全量查询话题列表
     */
    @GetMapping("/all")
    public AjaxResult all() {
        List<SysTopic> list = topicService.list();
        return AjaxResult.success(list);
    }
}